package com.oa.cms.converter;

import com.oa.cms.converter.base.BaseConvert;
import com.oa.cms.domain.dto.CmsConfigureDto;
import com.oa.cms.domain.entity.CmsConfigure;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/12/7.
 */
@Service
public class CmsConfigureConverter implements BaseConvert<CmsConfigure,CmsConfigureDto>{



    @Override
    public CmsConfigureDto convertToDto(CmsConfigure cmsConfigure) {
        if(cmsConfigure==null){
            return null;
        }
        return copyToDto(cmsConfigure);
    }

    @Override
    public CmsConfigure convertToEntity(CmsConfigureDto cmsConfigureDto) {
        if(cmsConfigureDto==null){
            return null;
        }
        return copyToEntity(cmsConfigureDto);
    }


    /**
     * entity转为dto
     * @param cc
     * @return
     */
    private static CmsConfigureDto copyToDto(CmsConfigure cc){
        CmsConfigureDto ccd=new CmsConfigureDto();
        ccd.setId(cc.getId());
        ccd.setFatherId(cc.getFatherId());
        ccd.setTopId(cc.getTopId());
        ccd.setConfigType(cc.getConfigType());
        ccd.setConfigName(cc.getConfigName());
        ccd.setIconPath(cc.getIconPath());
        ccd.setCreateTime(cc.getCreateTime());
        ccd.setStatus(cc.getStatus());
        ccd.setSort(cc.getSort());
        return ccd;
    }

    /**
     * dto转为entity
     * @param ccd
     * @return
     */
    private static CmsConfigure copyToEntity(CmsConfigureDto ccd){
        CmsConfigure cc=new CmsConfigure();
        cc.setId(ccd.getId());
        cc.setFatherId(ccd.getFatherId());
        cc.setTopId(ccd.getTopId());
        cc.setConfigType(ccd.getConfigType());
        cc.setConfigName(ccd.getConfigName());
        cc.setIconPath(ccd.getIconPath());
        cc.setCreateTime(ccd.getCreateTime());
        cc.setStatus(ccd.getStatus());
        cc.setSort(ccd.getSort());
        return cc;
    }
}
